<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            padding-bottom: 800px;
            padding-left: 30px;
        }

        #app {
            border: 1px solid #999;
            padding: 20px;
        }

        .cbox {
            border: 1px solid #999;
            padding: 20px;
            margin: 10px 0px;
        }
    </style>
</head>

<body>
    <div id="app">
        <h4>父组件</h4>
        <p>vue组件嵌套时，父组件的响应式仓库和元素渲染先完成执行，然后在根据定义顺序完成子组件的响应式仓库创建和页面渲染</p>
        <p>tempMsg：{{ tempMsg }}</p>
        <comp-a v-on:aaa="updateMsg"></comp-a>
    </div>
    <script type="module">
        // 加载 Vue3 的ESM 模块文件
        import { createApp } from "../../assets/vue3/vue.esm-browser.js"
        createApp({
            data() {
                return {
                    tempMsg:"父组件默认值"
                }
            },
            methods: {
                updateMsg(arg) {
                    console.log("父组件方法",arg);
                    this.tempMsg = arg;
                }
            },
            created() {
                console.log("createApp-created");
            },
            beforeMount() {
                console.log("createApp-beforeMount");
            },
            components: {
                CompA: {
                    template: `<div class="cbox">CompA</div>`,
                    data() {
                        return {
                            msg: "子组件的msg"
                        }
                    },
                    created() {
                        console.log("CompA-created",this.$attrs.onAaa);
                        this.$attrs.onAaa(this.msg);
                    },
                    beforeMount() {
                        console.log("CompA-beforeMount");
                    },
                },
            },
        }).mount("#app")
    </script>
</body>

</html>